package com.koron.common.web.controller;

import com.koron.common.core.util.mail.MailUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.mail.MessagingException;
import java.io.UnsupportedEncodingException;

/**
 * @ClassName MailController
 * @description
 * @Author zhouj
 * @Date 2021/4/27 10:22
 */
@Slf4j
@Controller
@RequestMapping("/email")
public class MailController {

    @Autowired
    private MailUtil mailUtil;

    /**
     * 发送邮件
     */
    @RequestMapping("/sendTest")
    public void sendMail() {
        String emailMsg = "测试发送邮件";
        try {
            // 发送普通文本邮件
            //mailUtil.sendMail("930480396@qq.com", "邮件发送测试", "<a href='https://www.baidu.com' >百度一下</a>",true);
            // 发送带附件的邮件
            mailUtil.sendAttachmentMail(new String[]{"18873269565@163.com"},null, "邮件发送测试", "<a href='https://www.baidu.com' >百度一下</a>",false,new String[]{"E:\\songzer.jpg","D:\\timg.jpg"});
        } catch (MessagingException | UnsupportedEncodingException e) {
            log.error(e.getMessage(), e);
        }
    }
}
